home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / NextAnswers / 1185_palette_archiving.rtf < prev    next >
Text File  |  1995-06-12  |  3KB  |  61 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f2\fmodern Ohlfs;}
  2. \paperw13040
  3. \paperh10800
  4. \margl120
  5. \margr120
  6. {\colortbl;\red0\green0\blue0;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ulnone\fs28\fc0\cf0 Q:  I've created a palette object with subviews.  These subviews are created within the 
  8. \b init:
  9. \b0  method for my object.  I store the 
  10. \b id's
  11. \b0  for these subviews in instance variables in the object.  When I instantiate one of these objects by dragging it from the palette, the subviews are there—they are visible—yet none of my code for resizing or accessing these subviews is working.  Why?\
  12. \
  13. Q:  When I instantiate and initialize one of my palette objects, the instance variables do not contain the values to which they were initialized.  What's going on?\
  14. \
  15. A:  If you debug the object that you have written within the context of InterfaceBuilder (try using 
  16. \b fprintf(stderr, ...)
  17. \b0  statements, if nothing else), you will discover that all of the instance variables and outlets are nil, even though at one point all of the instance variables were initialized and the objects to which the outlets once pointed still exist.  This is because the object is being archived and unarchived.  It is your responsibility to provide the specific archiving and unarchiving code for each of your objects.  This is accomplished within the 
  18. \b read:
  19. \b0  and 
  20. \b write:
  21. \b0  methods for your object.  Within those methods, you must read and write 
  22. \i all
  23. \i0  of the instance variables for your object—even the 
  24. \b id's
  25. \b0 .  If you do not do this, then instance variables contain bogus values, and outlets become disconnected even though the objects themselves exist.  (View archiving automatically handles archiving and unarchiving subviews.)\
  26. \
  27. Here is a code snippet which illustrates what you must do.  The object in question contains six instance variables: 1 string, 2 booleans, and 3 id's which point to subviews of the object.\
  28.  
  29. \fc1\cf1 \
  30.  
  31. \pard\tx620\tx1240\tx1860\tx2480\tx3100\tx3720\tx4340\tx4980\tx5600\tx6220\f2\fs22\fc1\cf1     - read:(NXTypedStream*)stream\
  32.     \{\
  33.         [super read:stream];\
  34.         NXReadTypes(stream,"cii", myTitle, &bordered, &gridEnabled);\
  35.         \
  36.     /* read in the id's for the outlets */\
  37.         myTitleField = NXReadObject(stream);\
  38.         grapherView = NXReadObject(stream);\
  39.         nameField = NXReadObject(stream);\
  40.         return self;\
  41.     \}\
  42. \
  43.     - write:(NXTypedStream*)stream\
  44.     \{\
  45.         [super write:stream];\
  46.         NXWriteTypes(stream,"cii", myTitle, &bordered, &gridEnabled);\
  47. \
  48.     /* write the id's for the outlets */\
  49.         NXWriteObjectReference(stream, myTitleField);\
  50.         NXWriteObjectReference(stream, grapherView);\
  51.         NXWriteObjectReference(stream, nameField);\
  52.         return self;\
  53.     \}\
  54.  
  55. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\fs28\fc1\cf1 \
  56. QA754\
  57. \
  58. Valid for 2.0, 3.0\
  59. \
  60.  
  61.